package com.miluGame.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.miluGame.entity.Role;
import com.miluGame.mapper.RoleMapper;
import com.miluGame.service.RoleService;
import com.miluGame.util.Util;

@Service
public class RoleServiceImpl implements RoleService {
	
	@Autowired
	private RoleMapper roleMapper;
	
	@Override
	public List queryAll(Object t) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void delete(String id) throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(Object t) throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public Object getById(String id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void add(Object t) throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public void delete(String[] ids) throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public List<Role> getMenusByRole(int pageSize, int pageNum) {
		Map paramMap = new HashMap();
		int count = roleMapper.countRoles();
		int pageSum  =  count%pageSize==0?(count/pageSize-1):(count/pageSize);													//总页数
		if(pageNum>pageSum){
			pageNum = pageSum;
		}
		paramMap.put("pageNum", pageNum);
		paramMap.put("pageSize", pageSize);
		paramMap.put("pageLine", pageNum*pageSize);
		paramMap.put("pageNum", pageNum);
		paramMap.put("pageSize", pageSize);
		List<Role> roles = roleMapper.queryRolesWithPage(paramMap);
		return roles;
	}

	@Override
	public int countRoles() {
		return roleMapper.countRoles();
	}

	@Override
	public int insertRole(String roleName, String roleDis,HttpServletResponse rsp) {
		if(roleName==null||roleName.trim().equals("")){
			Util.alert(rsp, "角色名称不能为空!添加失败");
			return 0;
		}else{
			Role role = new Role();
			role.setRoleName(roleName);
			role.setRoleDis(roleDis);
			return roleMapper.addRole(role);
		}
	}

	
}
